<template>
  <el-card
    class="design-container"
    v-loading="loading"
    :element-loading-text="loadinText"
  >
    <el-tabs type="card" @tab-click="changeTab" v-model="activeName">
      <el-tab-pane label="甲级资质" name="first" class="firstDesign">
        <el-table
          height="650"
          :data="firstDesignList"
          type="border-card"
          style="width: 100%"
          v-loading="loading"
          :element-loading-text="loadinText"
        >
          <el-table-column type="expand">
            <template slot-scope="props">
              <el-form label-position="left" class="demo-table-expand">
                <el-form-item label="公司名称">
                  <span>{{ props.row.cname }}</span>
                </el-form-item>
                <el-form-item label="有效期至">
                  <span>{{ props.row.date }}</span>
                </el-form-item>
                <el-form-item label="资质等级">
                  <span>{{ props.row.grade }}</span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column prop="cname" label="公司名称"> </el-table-column>
          <el-table-column prop="lperson" label="公司法人"></el-table-column>
          <template slot="empty">
            <el-empty description="暂无甲级设计资质"></el-empty>
          </template>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="乙级资质" name="second" class="secondDesign">
        <el-table
          height="650"
          :data="secondDesignList"
          type="border-card"
          style="width: 100%"
          v-loading="loading"
          :element-loading-text="loadinText"
        >
          <el-table-column type="expand">
            <template slot-scope="props">
              <el-form label-position="left" class="demo-table-expand">
                <el-form-item label="公司名称">
                  <span>{{ props.row.cname }}</span>
                </el-form-item>
                <el-form-item label="有效期至">
                  <span>{{ props.row.date }}</span>
                </el-form-item>
                <el-form-item label="资质等级">
                  <span>{{ props.row.grade }}</span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column prop="cname" label="公司名称"> </el-table-column>
          <el-table-column prop="lperson" label="公司法人"></el-table-column>
          <template slot="empty">
            <el-empty description="暂无乙级设计资质"></el-empty>
          </template>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="丙级资质" name="third" class="thirdDesign">
        <el-table
          height="650"
          :data="thirdDesignList"
          type="border-card"
          style="width: 100%"
          v-loading="loading"
          :element-loading-text="loadinText"
        >
          <el-table-column type="expand">
            <template slot-scope="props">
              <el-form label-position="left" class="demo-table-expand">
                <el-form-item label="公司名称">
                  <span>{{ props.row.cname }}</span>
                </el-form-item>
                <el-form-item label="有效期至">
                  <span>{{ props.row.date }}</span>
                </el-form-item>
                <el-form-item label="资质等级">
                  <span>{{ props.row.grade }}</span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column prop="cname" label="公司名称"> </el-table-column>
          <el-table-column prop="lperson" label="公司法人"></el-table-column>
          <template slot="empty">
            <el-empty description="暂无丙级设计资质"></el-empty>
          </template>
        </el-table>
      </el-tab-pane>
    </el-tabs>
    <!-- 分页组件 -->
    <div style="height: 60px; margin-top: 19px">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-sizes="[15, 30, 40]"
        :page-size="page_size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </el-card>
</template>

<script>
import {
  getFirstDesignListApi,
  getSecondDesignListApi,
  getThirdDesignListApi
} from '@/api/qualifications'
export default {
  name: 'design-page',
  created () {
    this.roleid = localStorage.getItem('crm-roleid')
    this.getFirstDesignList()
  },
  data () {
    return {
      roleid: 0,
      loading: false,
      loadinText: '',
      page: 1,
      page_size: 15,
      total: 0,
      activeName: 'first',
      // 甲级 设计资质资质
      firstDesignList: [],
      // 乙级 设计资质资质
      secondDesignList: [],
      // 丙级 设计资质资质
      thirdDesignList: []
    }
  },
  methods: {
    // 获取 设计资质甲级资质
    async getFirstDesignList () {
      // this.loading = true
      this.loadinText = '数据正在加载中!'
      const { data: res } = await getFirstDesignListApi(
        this.page,
        this.page_size
      )
      // console.log('获取 设计资质甲级资质', res)
      this.firstDesignList = [...res.data.lists]
      this.total = res.data.num
      this.loading = false
      this.loadinText = ''
    },
    // 获取 设计资质乙级资质
    async getSecondDesignList () {
      this.loading = true
      this.loadinText = '数据正在加载中!'
      const { data: res } = await getSecondDesignListApi(
        this.page,
        this.page_size
      )
      // console.log('获取 设计资质乙级资质', res)
      this.secondDesignList = [...res.data.lists]
      this.total = res.data.num
      this.loading = false
      this.loadinText = ''
    },
    // 获取 设计资质丙级资质
    async getThirdDesignList () {
      this.loading = true
      this.loadinText = '数据正在加载中!'
      const { data: res } = await getThirdDesignListApi(
        this.page,
        this.page_size
      )
      // console.log('获取 设计资质丙级资质', res)
      this.thirdDesignList = [...res.data.lists]
      this.total = res.data.num
      this.loading = false
      this.loadinText = ''
    },
    // 切换tab栏 重置页码  判断选择的是哪个tab栏
    changeTab () {
      this.page = 1
      this.page_size = 15
      this.total = 0
      this.activeNameChange()
    },
    // 切换第几页
    handleCurrentChange (val) {
      this.page = val
      this.activeNameChange()
    },
    // 手动更改页码
    handleSizeChange (val) {
      this.page_size = val
      this.activeNameChange()
    },
    // 判断哪个tab栏被选中
    activeNameChange () {
      if (this.activeName === 'first') {
        this.getFirstDesignList()
      } else if (this.activeName === 'second') {
        this.getSecondDesignList()
      } else if (this.activeName === 'third') {
        this.getThirdDesignList()
      }
    }
  },
  watch: {}
}
</script>

<style lang="scss" scoped>
.design-container {
  box-sizing: border-box;
  height: 837px;
  padding: 25px 40px 0px;
  .el-tabs {
    .el-tabs__item.is-active {
      background-color: #f5f7fa;
    }
  }
}
</style>
